package com.heima.admin.kafka.listener;

import com.alibaba.fastjson.JSON;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.common.constants.message.NewsAutoScanConstants;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @作者 itcast
 * @创建日期 2020/9/27 15:41
 **/
@Component
@Log4j2
public class WemediaNewsAutoListener {
    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @KafkaListener(topics = NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void recivedHandleMsg(ConsumerRecord<String,String> record){
        log.info("admin微服务中接收到kafka文章自动审核消息");
        if(record!=null){
            String id = JSON.parseObject(record.value(),String.class);
            log.info("消息体中 ==> 文章审核的id : {}",id);
            wemediaNewsAutoScanService.autoScanByMediaNewsId(Integer.valueOf(id));
        }
    }


}
